/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package post;
import java.io.*;
import java.util.*;

/**
 *
 * @author sean
 */
public class ProductReader {
    private BufferedReader reader;

    public ProductReader( File fileName ) throws FileNotFoundException
    {
        reader = new BufferedReader( new FileReader( fileName ) );
    }//end constructor

    public boolean hasMoreProducts() throws IOException
    {
        return reader.ready();
    }//end hasMoreProducts

    public ProductSpec getNextProduct() throws IOException
    {
        String inputLine = null;
        inputLine = reader.readLine();
        String upc = inputLine.substring(0, 4);
        String description = inputLine.substring(9, 28);
        Double price = Double.parseDouble(inputLine.substring(34));
        //System.out.println("U:" + upc + "P" + price );
        return new ProductSpec( upc, description, price );
    }//end getNextProduct
}//end ProductReader class
